// input检测

const regEmail = /\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/;
const regPhone = /^\d{11}$/;
// 数字,字母,字符至少包含两种
const regPassword = /(?!^[0-9]+$)(?!^[A-z]+$)(?!^[^A-z0-9]+$)$/;

const regOnlyNum = /^\d+$/;
const regIDCard = /^(^[1-9]\d{7}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}$)|(^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])((\d{4})|\d{3}[Xx])$)$/;
const checkIDCard = (val = '') => {
  if (!val) return 90;
  const flag = regIDCard.test(val);
  if (!flag) return 91;
  else return -1;
};
const checkNum = (val = '') => {
  const flag = regOnlyNum.test(val);
  if (!flag) return 81;
  else return -1;
};

const checkPhone = (val = '') => {
  if (!val) return 11;
  const flag = regPhone.test(val);
  if (!flag && val) return 10;
  else return -1;
};
const checkEmail = (val = '') => {
  if (!val) return 31;
  const flag = regEmail.test(val);
  if (!flag && val) return 30;
  else return -1;
};
const checkPassword = (val = '') => {
  if (!val) return 41;
  const flag = regPassword.test(val);
  if (!flag && val) return 40;
  if (val.length < 8 || val.length > 16) return 40;
  else return -1;
};
const checkRePassword = (val = '', pass = '') => {
  if (!val) return 41;
  if (!pass) return 51;
  if (val !== pass) return 50;
  const flag = regPassword.test(val);
  if (!flag && val) return 40;
  if (val.length < 8 || val.length > 16) return 40;
  else return -1;
};
const checkCaptcha = (val = '') => {
  if (!val) return 20;
  else return -1;
};

const checkImg = (val = '') => {
  if (!val) return 70;
  else return -1;
};
const checkFormErrorMsg = val => {
  switch (val) {
    case 10:
      return '请输入正确手机号';
    case 11:
      return '请输入手机号';
    case 20:
      return '请输入验证码';
    case 30:
      return '请输入正确的邮箱';
    case 31:
      return '请输入邮箱';
    case 40:
      return '密码应为大小写字母 数字 特殊字符中的2种且长度至少8位！';
    case 41:
      return '请输入密码！';
    case 50:
      return '两次密码不一致！';
    case 51:
      return '请确认输入密码！';
    case 60:
      return '手机号或邮箱输入有误！';
    case 61:
      return '请输入手机号或邮箱！';
    case 70:
      return '请输入图形验证码！';
    case 80:
      return '请输入！';
    case 81:
      return '请输入数字！';
    case 82:
      return '请正确输入！';
    case 90:
      return '请输入身份证号！';
    case 91:
      return '身份证号输入有误！';
    default:
      break;
  }
};
export default {
  checkIDCard,
  checkNum,
  checkImg,
  checkEmail,
  checkCaptcha,
  checkFormErrorMsg,
  checkPassword,
  checkRePassword,
  checkPhone
};
